<template>
  <div class="tree-container">
    <!--tree-->
    <!--:levStatus="levStatus"-->
    <!--:searchText.sync="selectId"-->
    <tree ref="tree"
          @treeGetlists="treeGetlists"
    ></tree>

    <div class="tree-container-right vw20">
      <!-- 这是组件要插入的地方 -->
      <div class="page-component-wrap animated fadeIn">
        <el-row style="margin:0px;margin-bottom: 10px;">
          <el-col :span="14">
          </el-col>

          <el-col :span="10">
            <!--<el-button type="primary" @click="$refs.devref.addDevice(0)" icon="el-icon-share">添加备件</el-button>-->
            <!--<el-button type="primary" @click="$refs.devref.addDevice(1)" icon="el-icon-share">发起申请备件</el-button>-->
          </el-col>
        </el-row>

        <!-- add edit item -->

        <!--:levStatus="levStatus"-->
        <auditedit ref="devref"
                   :treeNodeData.sync="treeNodeData"
                   :nodeId="nodeId"
                   @childGetList="tbgetList"
        ></auditedit>
        <!--table-->
        <el-tabs v-model="nodeId" @tab-click="tabClick" style="margin-top:15px;" type="border-card">
          <el-tab-pane v-for="item in tabMapOptions" :label="item.label" :key="item.key" :name="item.key">
            <tab-pane ref="tbaudit" v-if="nodeId==item.key" :type="item.key"
                      :nodeId="nodeId"
                      :param="param"
                      @handRowClick="handRowClick"
                      @auditRow="auditRow"
            />
          </el-tab-pane>
        </el-tabs>


      </div>
    </div>
  </div>
</template>
<script>
  // import tree from './comp/auditTree'
  import tree from './comp/deviceTree'
  import tabPane from './comp/tbAudit'
  import auditedit from './comp/auditEdit' // Secondary package based on el-pagination
  import {fetchGet} from '@/api/common'
  import {ERRS, SUCS} from '@/utils'

  export default {
    name: 'applyCode',
    components: {tree, auditedit, tabPane},

    data() {
      return {
        //弹出层
        listLoading: false,  //加载动画
        dialogStatus: '', //值对应textMap中的属性

        list: [],
        listQuery: {
          page: 1,
          size: 10, //每页几条
          number: 0, //当前页为第1页,从0计算
          searchText: '',
        },
        searchText: '',
        searchData: {},
        changeSearchData: [{}],
        treeNodeData: {}, //添加修改时保存父级信息

        //tabs
        tabMapOptions: [
          {label: '我的记录', key: 'myHiTask'},
          {label: '待提交', key: this.GLB.start_node},
          {label: '待审核', key: this.GLB.user_node},
          // {label: '已完成', key: this.GLB.end_node},
        ],
        nodeId:'myHiTask',
        param: {}, //流程转跳的传参row

      };
    },

    mounted() {
// console.log(this.$refs.tbaudit[0].getList);
      this.param = this.$route.params
      if (this.param && this.param.nodeId) {  //任务跳转过来
        this.nodeId = this.param.nodeId
        //审核
        if (this.param.hiParams && this.param.hiParams.codeEndId) {
          this.$refs.tree.getNodeSetClick(this.param.hiParams)
        } else {
          //提交保存
          let node = eval('(' + this.param.opFormJson + ')')
          this.$refs.tree.getNodeSetClick(node)
        }
      }
      // this.getList()
    },
    methods: {
      tbgetList(){
        this.$refs.tbaudit[0].getList();
      },
      tabClick(tab, event){
          //选项卡切换
          // console.log(this.nodeId);
      },
      handRowClick(row) {
        // this.tableRowClassName(row)
        // console.log(row);
        if (!row.hiParams.codeEndId) { //保存没提交
          let node = eval('(' + row.opFormJson + ')')
          console.log(node);
          this.$refs.tree.setCheckedKey(node.codeEndId)
        } else {
          this.$refs.tree.setCheckedKey(row.hiParams.codeEndId)
        }
      },

      auditRow(row) {
        this.$refs.devref.audit(row)
      },


      // tree点击分发事件
      treeGetlists(data) {
        this.treeNodeData = data
      },
      updateRow(row) {
        this.$refs.devref.updateDevice(row)
      },
      /*      //输入间隔查询
            querySearchAsync(queryString, cb) {

              if (queryString.length > 0) {
                fetchGet(`sparepartscode/parts/condition/false?page=1&size=1&searchText=${queryString}`).then(res => {

                  console.log(res);
                  if (res.code == 0) {
                    let dat = res.data.content;
                    console.log(dat);
                    if (dat.length > 0) {
                      cb(dat);
                      this.restaurants = dat
                    } else {
                      cb([]);
                      this.restaurants = []
                    }
                  } else {
                    ERRS(res.message)
                  }
                })
              } else {
                // cb([]);
              }
            },

            //搜索结果选择
            handleSelect(item) {
              this.searchText = item.codeExplain.fullCodeNo
              this.searchData = item
              this.$refs.tree.handleNodeClick(item.codeExplain.parent)

            },*/
    },
  }
</script>
<style lang="scss">
  @import './comp/index.scss';

</style>

